<?xml version="1.0" encoding="utf-8"?>
<Content xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:blueonionsoftware-com:bloget:runtime:data">
  <text>&lt;p&gt;Here's something from the Microsoft Research Site on adding the safety of C# to C and C++&lt;/p&gt;
&lt;p&gt;&lt;a href="http://research.microsoft.com/vault/"&gt;http://research.microsoft.com/vault/&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Today's safe programming languages, like C#, are great for weeding out many bugs in programs. Unfortunately, such languages are not suited to programmers who want to control the memory layout of their data structures or the lifetime of program's resources (like memory). Programmers who need this control are stuck with C or C++. Vault is a safe version of the C programming language, being developed at Microsoft Research, which provides the same level of safety as languages like C#, but allows a programmer to retain control over data layout and lifetime. A Vault program looks a lot like a C program:&lt;/p&gt;&lt;pre&gt;extern module Stdio : extern STDIO;
module Demo {

  void main() {
    Stdio.printf("hello, worldn");
  }
  
}&lt;/pre&gt;
&lt;p&gt;One difference is that Vault has a module system, which allow large programs to be assembled from parts. Like C# classes or COM components, a Vault module has an interface that lists the names and types of the exported functions and data. What's new is that a Vault interface also records the &lt;i&gt;rules&lt;/i&gt; for using these functions and data, which are checked &lt;i&gt;at compile time&lt;/i&gt;.&lt;/p&gt;
&lt;p&gt;Take files as an example. When a programmer uses an I/O library, she often has to obey rules like these: you must open a file before you read or write it; you can only read (write) from a file that is open for reading (writing); you cannot read or write a file after you close it; you must close every file that you open. Such rules are hopefully recorded in the I/O library's documentation. Disobeying such a rule might cause the program to crash or otherwise misbehave. With Vault, these rules become part of the types of the functions in the library's interface:&lt;/p&gt;&lt;pre&gt;interface IO {
  type FILE;
  &lt;font color=#ff0000&gt;tracked($F)&lt;/font&gt; FILE open_read(string)  &lt;font color=#ff0000&gt;[ new $F @ readable ]&lt;/font&gt;;
  &lt;font color=#ff0000&gt;tracked($F)&lt;/font&gt; FILE open_write(string) &lt;font color=#ff0000&gt;[ new $F @ writable ]&lt;/font&gt;;
  char read (&lt;font color=#ff0000&gt;tracked($F)&lt;/font&gt; FILE)        &lt;font color=#ff0000&gt;[ $F @ readable ]&lt;/font&gt;;
  void write (&lt;font color=#ff0000&gt;tracked($F)&lt;/font&gt; FILE, char) &lt;font color=#ff0000&gt;[ $F @ writable ]&lt;/font&gt;;
  void close (&lt;font color=#ff0000&gt;tracked($F)&lt;/font&gt; FILE) &lt;font color=#ff0000&gt;      [ -$F @ _ ]&lt;/font&gt;;
}&lt;/pre&gt;
&lt;p&gt;Like C header files, Vault interfaces contains function prototypes. To record interface rules, Vault provides the &lt;i&gt;tracked&lt;/i&gt; keyword to identify resources that the interface manipulates and &lt;i&gt;change specs&lt;/i&gt; that show what each function does to those resources. A function can create new resources, take away resources, and change the symbolic states associated with resources. Our I/O interface manipulates &lt;code&gt;FILE&lt;/code&gt; resources: the function &lt;code&gt;open_read&lt;/code&gt; returns a new &lt;code&gt;FILE&lt;/code&gt; resource in the &lt;code&gt;readable&lt;/code&gt; state; the function &lt;code&gt;open_write&lt;/code&gt; returns a new &lt;code&gt;FILE&lt;/code&gt; resource in the &lt;code&gt;writable&lt;/code&gt; state; the function &lt;code&gt;read&lt;/code&gt; takes a &lt;code&gt;FILE&lt;/code&gt; resource in the &lt;code&gt;readable&lt;/code&gt; state and leaves it in that state; the function &lt;code&gt;write&lt;/code&gt; takes a &lt;code&gt;FILE&lt;/code&gt; resource in the &lt;code&gt;writable&lt;/code&gt; state and leaves it in that state; and the function &lt;code&gt;close&lt;/code&gt; takes a &lt;code&gt;FILE&lt;/code&gt; resource in any state and releases that resource. Because these rules are part of the interface, the compiler will report an error if the programmer reads a file open for writing, writes a file open for reading, reads or writes a closed file, or forgets to close a file. &lt;/p&gt;
&lt;p&gt;This same rule checking allows a Vault programmer to allocate and deallocate data structures, with a compile-time guarantee that no dangling pointers are dereferenced and no memory is leaked! In short, Vault provides the layout and lifetime control of C with the safety of C#!&lt;/p&gt;&lt;img src ="http://flounder_aaeng/blogs/devnotes/aggbug/240.aspx" width = "1" height = "1" /&gt;</text>
  <last_update>2007-10-04T00:51:49.1750806Z</last_update>
  <source_title />
  <source_link />
  <comments />
  <references />
  <attachments />
</Content>